<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <title>配置</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="csrf-token" content="{:token()}">
    <link rel="stylesheet" href="/static/frontend/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/frontend/css/public.css" media="all">
    <style>
        .layui-form-item .layui-input-company {width: auto;padding-right: 10px;line-height: 38px;}
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <div class="layui-form layuimini-form">
            <input type="hidden" name="id" value="">
            <div class="layui-form-item">
                <label class="layui-form-label">工时显示格式</label>
                <div class="layui-input-block">
                    <input type="radio" name="format" value="his" title="时分秒" {$userConfig['format'] == 'his' ? 'checked' : ''}>
                    <input type="radio" name="format" value="day" title="日" {$userConfig['format'] == 'day' ? 'checked' : ''}>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">每日时间</label>
                <div class="layui-input-inline">
                    小时：<input type="number" name="hour" value="{$userConfig['hour']}" id="hour" required  lay-verify="required" autocomplete="off" class="layui-input" oninput="checkHour(this.value)">
                </div>
                <div class="layui-input-inline">
                    分钟：<input type="number" name="minute" value="{$userConfig['minute']}" id="minute" required  lay-verify="required" autocomplete="off" class="layui-input" oninput="checkMinute(this.value)">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="/static/frontend/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="/static/frontend/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use(['form','miniTab'], function () {
        var form = layui.form,
            layer = layui.layer,
            miniTab = layui.miniTab,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
            $.post('/frontend/personal-config-save', data.field, function (res) {
                if (res.code == 0) {
                    // 修改成功
                    layer.msg(res.msg, {
                        icon: 1,
                        time: 1000
                    },function () {
                        // 重新加载父页面
                        location.reload();
                    })
                } else if (res.code == 302) {
                    // 错误跳转
                    location.href = '/frontend/error/' + res.msg;
                } else {
                    // 修改失败
                    layer.msg(res.msg, {icon: 2});
                }
            }, 'json');
            return false;
        });

        // 自定义验证规则
        form.verify({

        })

    });

    function checkHour(value) {
        let re = /^[0-9]+$/;
        let result = re.test(value);
        if (result && value >= 0) {
            document.getElementById('hour').value = value;
        } else {
            document.getElementById('hour').value = 0;
        }
    }
    function checkMinute(value) {
        let re = /^[0-9]+$/;
        let result = re.test(value);
        if (result && value >= 0) {
            document.getElementById('minute').value = value;
        } else {
            document.getElementById('minute').value = 0;
        }
        if (value > 60) {
            document.getElementById('minute').value = 60;
        }
    }
</script>
</body>
</html>